package island.gotenyama.wand.field;

import island.gotenyama.wand.annotation.NumericAlpha;
import island.gotenyama.wand.annotation.FieldDefinition;
import island.gotenyama.wand.annotation.NotNull;
import island.gotenyama.wand.annotation.Length;
import island.gotenyama.wand.annotation.TableDefinition;
import island.gotenyama.wand.bean.AField;
import island.gotenyama.wand.enums.DBFieldType;
import island.gotenyama.wand.enums.JavaFieldType;
import island.gotenyama.wand.exception.FatalException;

import java.lang.reflect.Field;

/**
 * Passwordを連想するヒントのフィールドを定義する。
 * 
 * @author tk
 */
@TableDefinition(name = "password_hint", nameJp = "パスワードヒント", hasACmnField = true)
public enum PasswordHintField implements AField {

	@NotNull
	@Length(max = 200)
	@NumericAlpha
	@FieldDefinition(name = "code", nameJp = "コード", typeDB = DBFieldType.VARCHAR, typeJava = JavaFieldType.STRING)
	CODE,

	@NotNull
	@Length(max = 1000)
	@FieldDefinition(name = "description", nameJp = "説明", typeDB = DBFieldType.VARCHAR, typeJava = JavaFieldType.STRING)
	DESCRIPTION;

	@Override
	public Field getField() {
		try {
			return this.getClass().getDeclaredField(name());
		} catch (NoSuchFieldException e) {
			throw new FatalException("No Field.", e);
		}
	}

	@Override
	public FieldDefinition getFieldDefinition() {
		return getField().getAnnotation(FieldDefinition.class);
	}
}
